package pl.vanta.mjuzik2.impl.player.engine;

import java.util.Collection;

import pl.vanta.mjuzik2.impl.player.PlayerEvent;

/**
 * This class implements a threaded events launcher.
 */
public class BasicPlayerEventLauncher extends Thread
{
	private PlayerEvent						code		= PlayerEvent.UNKNOWN;
	private int								position	= -1;
	private double							value		= 0.0;
	private Object							description	= null;
	private Collection<BasicPlayerListener>	listeners	= null;
	private Object							source		= null;

	public BasicPlayerEventLauncher(PlayerEvent code, int position, double value, Object description,
			Collection<BasicPlayerListener> listeners, Object source)
	{
		this.code = code;
		this.position = position;
		this.value = value;
		this.description = description;
		this.listeners = listeners;
		this.source = source;
	}

	public void fire()
	{
		if (this.listeners != null)
		{
			BasicPlayerEvent event = new BasicPlayerEvent(this.source, this.code, this.position, this.value,
					this.description);

			for (BasicPlayerListener bpl : this.listeners)
			{
				bpl.stateUpdated(event);
			}
		}
	}

	@Override
	public void run()
	{
		fire();
	}
}